Prediting troll comments

Loading comment data


In [17]:
import pandas as pa
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import offsetbox
from sklearn.cluster import KMeans, MiniBatchKMeans
from sklearn.feature_extraction.text import CountVectorizer
from sklearn import (manifold, datasets, decomposition, ensemble,
                     discriminant_analysis, random_projection)

In [2]:
ytData = pa.read_csv("utube.csv",encoding ='ISO-8859-1')
print(ytData.shape)
ytData[1:5]


(4007, 8)
Out[2]:
comment title views dislikes commentCount likes replies id
1 What a lucky guy, got celebrated birthday on c... Nothing Compares 2 U (Live in LA w/ James Corden) 469414 263 1123 19392 0 mak_Cu9Wl6w
2 Love it Nothing Compares 2 U (Live in LA w/ James Corden) 469414 263 1123 19392 0 mak_Cu9Wl6w
3 no americans even knew who corden was several ... Nothing Compares 2 U (Live in LA w/ James Corden) 469414 263 1123 19392 0 mak_Cu9Wl6w
4 my birthday was the 22nd as well and we both s... Nothing Compares 2 U (Live in LA w/ James Corden) 469414 263 1123 19392 0 mak_Cu9Wl6w

In [3]:
vectorizer = CountVectorizer(min_df=1,stop_words="english")
X = vectorizer.fit_transform(ytData['comment'])
X


Out[3]:
<4007x9309 sparse matrix of type '<class 'numpy.int64'>'
	with 30914 stored elements in Compressed Sparse Row format>

In [4]:
X.toarray().shape


Out[4]:
(4007, 9309)

In [5]:
vectorizer.get_feature_names()


Out[5]:
['00',
 '000',
 '000ï',
 '021412',
 '03',
 '04',
 '05',
 '06',
 '08',
 '09',
 '0_0',
 '0m03s',
 '0m05s',
 '0m06s',
 '0m11s',
 '0m15s',
 '0m26s',
 '0m30s',
 '0m46s',
 '0m56s',
 '0mg',
 '0n',
 '0ï',
 '10',
 '100',
 '1000',
 '1000ï',
 '100k',
 '100mp',
 '100pct',
 '100x',
 '100ï',
 '101',
 '101ï',
 '10mps',
 '10th',
 '10x',
 '10â',
 '10ï',
 '11',
 '11000',
 '11044145',
 '11thï',
 '11â',
 '11ï',
 '12',
 '120',
 '1234567890',
 '123paul',
 '127ï',
 '12m08s',
 '12th',
 '12â',
 '13',
 '1334x750',
 '13â',
 '14',
 '142823291',
 '143',
 '145',
 '14â',
 '15',
 '150',
 '15â',
 '16',
 '16â',
 '17',
 '170',
 '17m20s',
 '17â',
 '18',
 '180lb',
 '182',
 '18â',
 '19',
 '1934ï',
 '1954',
 '1985',
 '1995',
 '19k',
 '19â',
 '1m00s',
 '1m08s',
 '1m11s',
 '1m13s',
 '1m16s',
 '1m22s',
 '1m25s',
 '1m29s',
 '1m35s',
 '1m42s',
 '1m46s',
 '1m49s',
 '1m52s',
 '1secret',
 '1st',
 '1ï',
 '20',
 '200',
 '2005',
 '2008',
 '2009',
 '200k',
 '2010',
 '2011',
 '2012',
 '2013',
 '2015',
 '2016',
 '2016ï',
 '202',
 '2020',
 '2072',
 '2075',
 '2085',
 '20oz',
 '20s',
 '20seconds',
 '20th',
 '20â',
 '21',
 '2100',
 '21st',
 '21â',
 '22',
 '22nd',
 '22â',
 '22ï',
 '23apple',
 '23dicksoutforharambe',
 '23ghettoabortion',
 '23hbd',
 '23ijs',
 '23listen',
 '23maga',
 '23makelogicmandatory',
 '23makewitchhousegreatagain',
 '23mcgregor',
 '23nbcfail',
 '23nike',
 '23rio2016',
 '23teamnote7',
 '23throwback',
 '23trumptrain',
 '23usa',
 '23wardiaz',
 '23youshouldakilledmewhenyouhadthechance',
 '23â',
 '24',
 '24hrs',
 '24â',
 '25',
 '250',
 '25â',
 '26',
 '2600',
 '26th',
 '26â',
 '27',
 '27m40s',
 '28th',
 '29',
 '2jgpvq3g',
 '2k',
 '2l2hqdpt92u',
 '2m10s',
 '2m11s',
 '2m12s',
 '2m13s',
 '2m17s',
 '2m18s',
 '2m29s',
 '2m34s',
 '2nd',
 '2ndï',
 '2u',
 '2x',
 '2â',
 '2ï',
 '30',
 '300',
 '30m',
 '319',
 '32',
 '32yr',
 '32yrs',
 '33',
 '333',
 '33ï',
 '34',
 '34m40s',
 '35',
 '357',
 '36',
 '360p',
 '37154700',
 '375',
 '39',
 '397',
 '3d',
 '3gs',
 '3m',
 '3m03s',
 '3m04s',
 '3m10s',
 '3rd',
 '3x',
 '3yr',
 '3â',
 '3î',
 '3ï',
 '40',
 '400ï',
 '408',
 '40m',
 '41',
 '42',
 '420',
 '42m00s',
 '43',
 '45',
 '46',
 '49',
 '4in1ð',
 '4m',
 '4m45s',
 '4m46s',
 '4s',
 '4sponsors',
 '4th',
 '4thï',
 '4â',
 '4ï',
 '50',
 '500',
 '51',
 '52',
 '54th',
 '56',
 '562',
 '56m',
 '56mï',
 '57',
 '59',
 '5m12s',
 '5mil',
 '5th',
 '5thï',
 '5wxut6ocyyg',
 '5â',
 '5ï',
 '60',
 '60ft',
 '61ffojfy0',
 '627',
 '64',
 '66',
 '666',
 '696',
 '6m29s',
 '6p',
 '6s',
 '6sï',
 '6wuwffka',
 '6xpiwq04bzm',
 '6â',
 '70',
 '700',
 '70m',
 '72',
 '720p',
 '7420',
 '767069766058143748',
 '767835735433023489',
 '7yr',
 '7â',
 '7ï',
 '80',
 '820',
 '836',
 '85',
 '8dï',
 '8m57s',
 '8th',
 '8â',
 '8ï',
 '90',
 '90s',
 '911',
 '918108743962ï',
 '95',
 '97',
 '98',
 '99',
 '99pct',
 '9gaggers',
 '9gagï',
 '9â',
 '_xxpx3rq',
 'aa',
 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
 'aaaaaaaaaaaaaï',
 'aah',
 'aahï',
 'aaliya',
 'abandoned',
 'abandonedï',
 'abchor',
 'abia',
 'ability',
 'abilty',
 'able',
 'abnormal',
 'aboriginal',
 'aborted',
 'abortion',
 'abortionï',
 'aboutï',
 'abroad',
 'absoloute',
 'absolut',
 'absolutely',
 'abstain',
 'abuzz',
 'academia',
 'academy',
 'acasa',
 'acc',
 'accent',
 'accept',
 'acceptable',
 'acceptat',
 'accepted',
 'accesories',
 'access',
 'accident',
 'accidentally',
 'accidents',
 'accomplished',
 'accomplishment',
 'according',
 'accross',
 'accurate',
 'accusation',
 'ace',
 'aceasta',
 'aceeasi',
 'acei',
 'acelaå',
 'acest',
 'acestei',
 'acestora',
 'achieve',
 'achieved',
 'achievement',
 'achizitioneaza',
 'achiziè',
 'acid',
 'acidï',
 'ackbaring',
 'acknowledge',
 'aclares',
 'acolo',
 'acompaniat',
 'acord',
 'acountsð',
 'acquired',
 'act',
 'acted',
 'actin',
 'acting',
 'action',
 'actionarii',
 'actions',
 'actionï',
 'actiune',
 'actiunea',
 'active',
 'actor',
 'actors',
 'actress',
 'acts',
 'actual',
 'actuale',
 'actually',
 'acum',
 'acè',
 'ad',
 'adaaaaaaaaamï',
 'adam',
 'adamant',
 'adamï',
 'add',
 'addict',
 'addictions',
 'addition',
 'additional',
 'address',
 'adds',
 'adjective',
 'adjectives',
 'adjustments',
 'admiration',
 'admire',
 'admit',
 'admitting',
 'adolescentii',
 'adolf',
 'adopt',
 'adopts',
 'adorable',
 'adorableï',
 'adore',
 'adoreï',
 'ads',
 'aduca',
 'adult',
 'adultery',
 'adults',
 'adunarii',
 'aduni',
 'adus',
 'advanced',
 'advantage',
 'advert',
 'advertising',
 'advertisment',
 'advising',
 'advisor',
 'ae',
 'aerosmith',
 'af',
 'afaceri',
 'afar',
 'affect',
 'affection',
 'affirmative',
 'afford',
 'afi',
 'afirmat',
 'afise',
 'afli',
 'afr',
 'afraid',
 'africa',
 'african',
 'africans',
 'africaï',
 'afternoon',
 'afï',
 'againï',
 'againð',
 'age',
 'aged',
 'agencyâ',
 'agenda',
 'agent',
 'agentï',
 'agenè',
 'ages',
 'aginst',
 'ago',
 'agoï',
 'agree',
 'agreeing',
 'agrees',
 'agreeï',
 'aguilera',
 'ah',
 'ahaha',
 'ahahah',
 'ahahahaahahaha',
 'ahahahah',
 'ahahahahahaha',
 'ahahahhaha',
 'ahead',
 'ahem',
 'ahhhh',
 'ahhhhï',
 'ahjhhhhhhhï',
 'ahole',
 'ai',
 'aia',
 'aiba',
 'aici',
 'aid',
 'aids',
 'aimed',
 'ain',
 'aint',
 'airoplane',
 'airplane',
 'airwaves',
 'aiurea',
 'ajung',
 'ajunga',
 'ajunge',
 'ajuns',
 'ajunse',
 'ajutat',
 'ajute',
 'aka',
 'akbar',
 'akron',
 'al',
 'ala',
 'alaba',
 'alahiym',
 'alaturi',
 'alb',
 'alberto',
 'albino',
 'album',
 'albums',
 'albumï',
 'alcohol',
 'ale',
 'alea',
 'alerted',
 'alertï',
 'ales',
 'alicia',
 'alina',
 'alive',
 'aliveï',
 'allah',
 'allahu',
 'allngoodï',
 'allow',
 'allowed',
 'allows',
 'allrightï',
 'allï',
 'alongside',
 'alot',
 'alreadyï',
 'alright',
 'als',
 'alsoim',
 'alsphat',
 'alt',
 'alta',
 'altar',
 'altcineva',
 'alte',
 'altfel',
 'altä',
 'alè',
 'amanda',
 'amateur',
 'amateurs',
 'amazed',
 'amazing',
 'amazingï',
 'amazingð',
 'ambalat',
 'ambassadors',
 'amber',
 'ambivalence',
 'amendaå',
 'amendezi',
 'amenï',
 'america',
 'american',
 'americane',
 'americanii',
 'americans',
 'americanï',
 'americaï',
 'amestec',
 'amiright',
 'amk',
 'ammo',
 'amnesty',
 'amoled',
 'amounts',
 'amp',
 'amunzat',
 'amusing',
 'anafului',
 'ancestors',
 'anchor',
 'anchored',
 'anderson',
 'android',
 'angaleng',
 'angel',
 'angelina',
 'angle',
 'angriest',
 'angrily',
 'angry',
 'ani',
 'anikï',
 'animal',
 'animals',
 'animalï',
 'animation',
 'animations',
 'anna',
 'anniethingï',
 'annihilated',
 'annnnnnd',
 'annoyance',
 'annoying',
 'annoyingï',
 'annual',
 'ans',
 'answer',
 'answered',
 'answersï',
 'ant',
 'antarctica',
 'anthem',
 'anthony',
 'anti',
 'antivirus',
 'anxiousness',
 'anybody',
 'anymore',
 'anymoreï',
 'anyoneï',
 'anythin',
 'anythingï',
 'anythingð',
 'anytime',
 'anyways',
 'anywaysï',
 'anywayï',
 'anï',
 'aparent',
 'aparitia',
 'apart',
 'ape',
 'apeshit',
 'apk',
 'aplicatie',
 'apoi',
 'apologies',
 'apologise',
 'apologize',
 'apologizes',
 'apology',
 'app',
 'appalachian',
 'apparent',
 'apparently',
 'appeared',
 'apperently',
 'applaud',
 'applause',
 'apple',
 'apples',
 'applications',
 'applied',
 'apply',
 'appreciate',
 'appreciated',
 'appreciates',
 'appropriate',
 'approx',
 'apps',
 'appï',
 'april',
 'aprobada',
 'ar',
 'ara',
 'arab',
 'arabic',
 'aratä',
 'archaic',
 'archives',
 'arctic',
 'arcul',
 'ard',
 'area',
 'areas',
 'areaï',
 'aren',
 'arena',
 'arent',
 'arguably',
 'arguing',
 'argument',
 'arguments',
 'ari',
 'ariana',
 'arianaï',
 'arianna',
 'arm',
 'armata',
 'armor',
 'arms',
 'army',
 'armyï',
 'armï',
 'arrogant',
 'arse',
 'arsed',
 'arta',
 'articles',
 'articulate',
 'artificial',
 'artistice',
 'artiè',
 'arty',
 'arunce',
 'arä',
 'asa',
 'asadar',
 'asapï',
 'asemenea',
 'asfï',
 'ashame',
 'ashamed',
 'asif',
 'asigurare',
 'asigurat',
 'asistatilor',
 'ask',
 'asked',
 'asking',
 'asleep',
 'aspect',
 'aspecte',
 'ass',
 'assange',
 'assassinated',
 'assassination',
 'assault',
 'assaulted',
 'asses',
 'asshoe',
 'asshoes',
 'asshole',
 'assholes',
 'assholesï',
 'assholeï',
 'assist',
 'assistant',
 'associate',
 'assrape',
 'assumed',
 'assumes',
 'assuming',
 'assï',
 'asta',
 'astaï',
 'astea',
 'astfel',
 'astia',
 'asume',
 'asumä',
 'aswell',
 'asï',
 'atat',
 'atata',
 'atatea',
 'atatia',
 'ate',
 'athe',
 'athlete',
 'athletes',
 'athletic',
 'ati',
 'atins',
 'atitudinea',
 'atleast',
 'atom',
 'atrocity',
 'ats',
 'attack',
 'attacked',
 'attacking',
 'attacks',
 'attempt',
 'attempted',
 'attempts',
 'attending',
 'attention',
 'attentionï',
 'attic',
 'attila',
 'attitude',
 'attract',
 'attracted',
 'attraction',
 'attractive',
 'atucally',
 'atunci',
 'atã',
 'au',
 'audience',
 'audio',
 'audio_start',
 'audit',
 'august',
 'aunt',
 'auntie',
 'aurul',
 'australia',
 'autisticï',
 'automat',
 'automata',
 'auxiliare',
 'av',
 'avand',
 'avea',
 'aveau',
 'avem',
 'avenge',
 'avenging',
 'average',
 'averea',
 'aveti',
 'avioanele',
 'avoid',
 'avut',
 'award',
 'aware',
 'away',
 'awe',
 'awesome',
 'awesomeï',
 'awful',
 'awfulï',
 'awh',
 'awhhh',
 'awing',
 'aww',
 'awwnn',
 'awww',
 'awwww',
 'awwwwwe',
 'aye',
 'ayeï',
 'ayye',
 'ayyy',
 'ayyyyyyyï',
 'azi',
 'aè',
 'aï',
 'b17',
 'b4',
 'ba',
 'baaaaaadddd',
 'babaï',
 'babble',
 'babbling',
 'babe',
 'babies',
 'baby',
 'babying',
 'babyï',
 'backdoors',
 'backflipï',
 'background',
 'backing',
 'backk',
 'backkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkï',
 'backs',
 'backwater',
 'backï',
 'backð',
 'bad',
 'badass',
 'badly',
 'badlyï',
 'badmamajamaï',
 'badï',
 'bae',
 'baffling',
 'baffoon',
 'bag',
 'baga',
 'bagam',
 'bagä',
 'bahahahahï',
 'bai',
 'baiat',
 'baietii',
 'bait',
 'baiting',
 'baitï',
 'bala',
 'baladä',
 'balance',
 'balanced',
 'bald',
 'baldwin',
 'ball',
 'ballondor',
 'ballondors',
 'balls',
 'ballsed',
 'ballsï',
 'ballï',
 'balor',
 'balors',
 'ban',
 'banana',
 'bananas',
 'banca',
 'band',
 'bandage',
 'banditi',
 'bands',
 'bandâ',
 'bandï',
 'bang',
 'banged',
 'bangï',
 'bani',
 'banii',
 'bank',
 'banned',
 'banning',
 'banterï',
 'bapple',
 'bar',
 'barber',
 'barca',
 'barely',
 'baresi',
 'barker',
 'barks',
 'barrel',
 'barricade',
 'base',
 'baseball',
 'baseballï',
 'based',
 'basement',
 'bash',
 'bashing',
 'basic',
 'basically',
 'basis',
 'basket',
 'basketball',
 'basorelieful',
 'bass',
 'bastard',
 'bastardsï',
 'basten',
 'bate',
 'bath',
 'bathing',
 'bathroom',
 'baths',
 'batistuta',
 'batman',
 'batmangalch',
 'batshit',
 'battery',
 'battle',
 'battyï',
 'batut',
 'batä',
 'bay',
 'bbc',
 'bc',
 'bcuz',
 'bday',
 'beach',
 'beacuse',
 'beans',
 'bear',
 'beardï',
 'beast',
 'beasts',
 'beat',
 'beating',
 'beats',
 'beau',
 'beautiful',
 'beautifulï',
 'beauty',
 'beautï',
 'bebeï',
 'beck',
 'beckenb',
 'beckenbauer',
 'bed',
 'bedroom',
 'beef',
 'beenï',
 'beepers',
 'beer',
 'beforeï',
 'begging',
 'begin',
 'beginning',
 'beginnings',
 'begins',
 'begun',
 'behave',
 'behaving',
 'behavior',
 'behaviours',
 ...]

In [6]:
X[1].toarray().sum()


Out[6]:
9

In [7]:
km = MiniBatchKMeans(n_clusters=10, init='k-means++', n_init=1,init_size=1000, batch_size=1000, verbose=0)

In [8]:
km.fit(X)


/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1279: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, init_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:630: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, init_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
/Users/zackakil/anaconda/envs/dev/lib/python3.5/site-packages/sklearn/cluster/k_means_.py:1328: DeprecationWarning: This function is deprecated. Please call randint(0, 4006 + 1) instead
  0, n_samples - 1, self.batch_size)
Out[8]:
MiniBatchKMeans(batch_size=1000, compute_labels=True, init='k-means++',
        init_size=1000, max_iter=100, max_no_improvement=10, n_clusters=10,
        n_init=1, random_state=None, reassignment_ratio=0.01, tol=0.0,
        verbose=0)

In [9]:
y_pred = KMeans(n_clusters=10, random_state=101).fit_predict(X)

In [10]:
y_pred


Out[10]:
array([3, 3, 3, ..., 3, 3, 3], dtype=int32)

In [12]:
def plot_embedding(X, title=None):
#     x_min, x_max = np.min(X, 0), np.max(X, 0)
#     X = (X - x_min) / (x_max - x_min)

    plt.figure()
    ax = plt.subplot(111)
#     for i in range(X.shape[0]):
#         plt.text(X[i, 0], X[i, 1])

#     if hasattr(offsetbox, 'AnnotationBbox'):
#         # only print thumbnails with matplotlib > 1.0
#         shown_images = np.array([[1., 1.]])  # just something big
#         for i in range(digits.data.shape[0]):
#             dist = np.sum((X[i] - shown_images) ** 2, 1)
#             if np.min(dist) < 4e-3:
#                 # don't show points that are too close
#                 continue
#             shown_images = np.r_[shown_images, [X[i]]]
#             imagebox = offsetbox.AnnotationBbox(
#                 offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),
#                 X[i])
#             ax.add_artist(imagebox)
    plt.xticks([]), plt.yticks([])
    if title is not None:
        plt.title(title)
    plt.show()

In [13]:
plot_embedding(X)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-b0bde112d3f7> in <module>()
----> 1 plot_embedding(X)

<ipython-input-12-04ca81928002> in plot_embedding(X, title)
      3 #     X = (X - x_min) / (x_max - x_min)
      4 
----> 5     plt.figure()
      6     ax = plt.subplot(111)
      7 #     for i in range(X.shape[0]):

AttributeError: module 'matplotlib' has no attribute 'figure'

In [14]:
rp = random_projection.SparseRandomProjection(n_components=2, random_state=42)
X_projected = rp.fit_transform(X)
plot_embedding(X_projected, "Random Projection of the digits")


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-bf42717a2ccb> in <module>()
      1 rp = random_projection.SparseRandomProjection(n_components=2, random_state=42)
      2 X_projected = rp.fit_transform(X)
----> 3 plot_embedding(X_projected, "Random Projection of the digits")

<ipython-input-12-04ca81928002> in plot_embedding(X, title)
      3 #     X = (X - x_min) / (x_max - x_min)
      4 
----> 5     plt.figure()
      6     ax = plt.subplot(111)
      7 #     for i in range(X.shape[0]):

AttributeError: module 'matplotlib' has no attribute 'figure'

In [ ]:
plt.figure()
plt.plot(X[1:10][1,2,3].toarray())
plt.show()

In [ ]: